package com.ruoyi.hkCamera.common;

import cn.hutool.extra.spring.SpringUtil;
import com.ruoyi.hkCamera.service.CameraService;
import com.sun.jna.Pointer;

import java.util.HashMap;
import java.util.Map;

/**
 * 报警布防回调方法
 */
public class AlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {

    @Override
    public boolean invoke(int param1Int1, HCNetSDK.NET_DVR_ALARMER param1NET_DVR_ALARMER, Pointer param1Pointer1, int param1Int2, Pointer param1Pointer2) {
        this.alarmDataHandle(param1Int1, param1NET_DVR_ALARMER, param1Pointer1, param1Int2, param1Pointer2);
        return true;
    }

    private void alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
        // 交通抓拍结果(新报警信息)
        if (lCommand == HCNetSDK.COMM_ITS_PLATE_RESULT) {
            HCNetSDK.NET_ITS_PLATE_RESULT strItsPlateResult = new HCNetSDK.NET_ITS_PLATE_RESULT();
            strItsPlateResult.write();
            Pointer pItsPlateInfo = strItsPlateResult.getPointer();
            pItsPlateInfo.write(0L, pAlarmInfo.getByteArray(0L, strItsPlateResult.size()), 0, strItsPlateResult.size());
            strItsPlateResult.read();
            //进行业务逻辑处理
            Map<String, Object> param = new HashMap<>();
            param.put("strItsPlateResult", strItsPlateResult);
            param.put("lUserID", pAlarmer.lUserID);
            // 回调方法
            this.captureCallBack(param);
        }
    }

    /**
     * 相机抓拍回调
     */
    private void captureCallBack(Map<String, Object> param) {
        CameraService cameraService = SpringUtil.getBean(CameraService.class);
        cameraService.captureCallBack(param);
    }
}
